// let baseUrl = 'http://47.103.51.84:9091/'
let baseUrl = 'http://127.0.0.1:7777/'
let request = function(url, data = {}, method = 'GET') {
	return new Promise((resole, reject) => {
		uni.showLoading({
			title:'加载中...'
		})
		uni.request({
			url: baseUrl + url,
			method: method,
			data: data,
			header: {
				'Content-Type': 'application/json;charset=utf-8',
				'token':uni.getStorageSync('token')
			},
			success(res) {
				uni.hideLoading()
				if (res.statusCode == 200 && res.data.code == 0) {
					resole(res.data)
					return
				}
				uni.showToast({
					title: '请求失败',
					icon:'none'
				})
				resole(res.data)
			},
			fail(err) {
				uni.hideLoading()
				uni.showToast({
					title: '请求失败',
					icon:'none'
				})
				reject(err)
			}
		})
	})
}

let post = function(url,data){
	return request(url,data,"POST")
}
let get = function(url,data){
	return request(url,data)
}

export {post,get,request}
